<CFSET sMessPostApproval="OT Application was successfully posted.">
<CFQUERY NAME="qryECINTKOTPERMIT" DATASOURCE="#client.company_dsn#">
	SELECT *
	FROM ECINTKOTPERMIT
	WHERE ROUTEID = '#GetRecord.ROUTEID#'
</CFQUERY>

<CFIF qryECINTKOTPERMIT.RecordCount>
	<CFTRANSACTION>
	<CFTRY>
		<!--- Maximum of 100 employees subject for force leave --->
		<CFLOOP INDEX="x" FROM="1" TO="100">
			<CFIF IsDefined("qryECINTKOTPERMIT.PERSONNELIDNO#x#") AND Evaluate("qryECINTKOTPERMIT.PERSONNELIDNO" & x) NEQ "">
				<CFSET sPIN=Evaluate("qryECINTKOTPERMIT.PERSONNELIDNO" & x)>
				<CFSET sGraveYard=Evaluate("qryECINTKOTPERMIT.GRAVEYARD" & x)>
				<CFSET sOTType=Evaluate("qryECINTKOTPERMIT.OTTYPE" & x)>
				<CFSET sChargeToLeave=Evaluate("qryECINTKOTPERMIT.CHARGETOLV" & x)>
				<CFSET sLVToCharge=Evaluate("qryECINTKOTPERMIT.LVTYPETOCHARGE" & x)>
				<CFSET dOTDate=qryECINTKOTPERMIT.REFERENCEDATE>

				<CFIF qryECINTKOTPERMIT.BREAKMIN NEQ "">
					<CFSET nBreakMin=qryECINTKOTPERMIT.BREAKMIN>
				<CFELSE>
					<CFSET nBreakMin=0>
				</CFIF>

				<CFIF sGraveYard IS "Y">
					<CFIF sOTType IS "A">
						<CFSET dOTDate=DateAdd("d", 1, dOTDate)>
					</CFIF>
				</CFIF>

				<CFQUERY NAME="qryCINLEAVEAPPSM" DATASOURCE=#client.company_dsn#>
					INSERT INTO CINTKOTPERMIT
						(PERSONNELIDNO,
						REFERENCEDATE,
						STARTINGTIME,
						APPROVED,
						BREAKMIN,
						CHARGETOLV,
						ENDINGTIME,
						LEAVETYPE,
						OTDATE,
						REMARKS,
						WITHBREAK,
						DOCNUMBER)
					VALUES
						('#sPIN#',
						 #CreateODBCDate(qryECINTKOTPERMIT.REFERENCEDATE)#,
						 '#qryECINTKOTPERMIT.STARTINGTIME#',
						 'Y',
						 #nBreakMin#,
						 '#sChargeToLeave#',
						 '#qryECINTKOTPERMIT.ENDINGTIME#',
						 '#sLVToCharge#',
						 #CreateODBCDate(dOTDate)#,
						 'Batch OT Application from iBOS/e',
						 '#qryECINTKOTPERMIT.WITHBREAK#',
						 '#qryECINTKOTPERMIT.DOCNUMBER#')
				</CFQUERY>
			</CFIF>
		</CFLOOP>

		<CFTRANSACTION ACTION="COMMIT"/>
		<CFCATCH TYPE="Database">
			<CFTRANSACTION ACTION="ROLLBACK"/>
			<CFSET sMessPostApproval="Error in post-approval activity ...<br><br>#CFCATCH.message# #CFCATCH.DETAIL#">
		</CFCATCH>
	</CFTRY>
	</CFTRANSACTION>
<CFELSE>
	<CFSET sMessPostApproval="WARNING!!! OT Application was not posted. Application form is missing.<BR>Please contact your administrator.">
</CFIF>